using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using ToolsLayer;
using Webcar.BLL;

namespace Webcar.Controls.View
{
    public partial class CarDiscardView : System.Web.UI.UserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            GridViewStyler gvs = new GridViewStyler(this.GridView1);
            gvs.SetStyle();
        }
        public string SQL
        {
            get
            {
                return ViewState["sqlssss"]==null?"":ViewState["sqlssss"].ToString();
            }
            set
            {
                ViewState["sqlssss"] = value;
            }
        }
        public void InitView(string dept, string start_date, string end_date)
        {
            string sql = "";
            if (dept == "all")
            {
                sql = @"select 0 rowid,d.car_note,a.operator,convert(varchar(10),a.discard_date,120) as discard_date,a.cause
                ,b.DEPT_CODE,b.dept_name as dept_name,d.record_no,d.assdept_cn
                 from bs_car_discard a,dept b,v_bs_car_record d
                where a.dept_code = b.dept_code 
                and a.car_no = d.car_no and convert(varchar(10),a.discard_date,120) between '{0}' and '{1}'
                order by b.dept_code";
                sql = string.Format(sql, start_date, end_date);
            }
            else
            {
                sql = @"select 0 rowid,d.car_note,a.operator,convert(varchar(10),a.discard_date,120) as discard_date,cause
                    ,b.DEPT_CODE,b.dept_name as dept_name,d.record_no,d.assdept_cn
                     from bs_car_discard a,dept b,v_bs_car_record d
                    where a.dept_code = b.dept_code 
                    and a.car_no = d.car_no and convert(varchar(10),a.discard_date,120) between '{0}' and '{1}'
                    and a.dept_code='{0}' order by b.dept_code";
                sql = string.Format(sql, dept, start_date, end_date);
            }
            DataSet ds = ToolsLayer.DB.ExecuteDataset(sql);
            int i = 0;
            foreach (DataRow row in ds.Tables[0].Rows)
            {
                row["rowid"] = ++i;
            }
            this.SQL = sql;
            this.GridView1.DataSource = ds;
            this.GridView1.DataBind();
        }
    }
}